/**
 * @param {number[]} values
 * @return {number}
 */
 var minScoreTriangulation = function(values) {
  let arr = [],res =[]
  bc(0,1)

  function bc(index,num){ 
    if(arr.length==3){
      res.push(num)
      return
    }

    for(let i=index;i<values.length;i++){
      arr.push(values[i])
      num*=values[i]
      bc(i+1,num)
      num/=values[i]
      arr.pop()
    }
  }

  res.sort((a,b)=>a-b)
  let total=0
  for (let i = 0; i < values.length-2; i++) {
    total+=res[i]
    
  }



  return total
};